// components/like/index.js
Component({
  properties: {
    like: {type:Boolean, value:false},
    count: {type:Number, value:0},
    readOnly: {type:Boolean, value:false},
  },

  data: {
    yesUrl: '../images/like.png',
    noUrl: '../images/dislike.png'
  },

  methods: {
    onLike: function(event) {
      if (this.properties.readOnly) return;
      let like = this.properties.like;
      let count = this.properties.count;
      count = like ? count-1 : count+1;
      this.setData({
        count,
        like: !like
      })

      // 激活调用页面的like事件
      let behavior = this.properties.like ? 'like' : 'cancel';
      this.triggerEvent('like', {
        behavior
      }, {});
    }
  }
})
